package com.sense.endpoint;

import com.sense.common.exception.BizException;
import com.sense.common.lang.BizCode;
import com.sense.common.lang.annotation.JsonResponse;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Slf4j
@JsonResponse
@RequestMapping("test")
public class TestController {

    @GetMapping("string")
    public String test() {
        return "test";
    }

    @GetMapping("obj")
    public UserInfo userInfo() {
        UserInfo info = new UserInfo();
        info.setId("1");
        info.setName("test");
        return info;
    }

    @GetMapping("obj2")
    @JsonResponse(ignore = true)
    public UserInfo userInfo2() {
        UserInfo info = new UserInfo();
        info.setId("1");
        info.setName("test");
        log.info("user-info:{}",info);
        return info;
    }

    @GetMapping("obj3")
    @JsonResponse(ignore = true)
    public UserInfo userInfo3() {
        UserInfo info = null;
        if (info == null) {
            throw new BizException(BizCode.USER_NOT_FOUND);
        }
        return info;
    }

}
@Data
class UserInfo {
    private String id;
    private String name;
}